package com.dal.thread;

/**
 * @description 多线程锁
 * @ClassName Demo04
 * @Author jian
 * @Date 9:43 PM 2022/12/14
 **/
public class Demo04 implements Runnable{

    static int a = 0;

    public synchronized void create(){
        a++;
    }
    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            create();
        }
    }


    public static void main(String[] args) throws InterruptedException {
        Demo04 demo04 = new Demo04();
        Thread t1 = new Thread(demo04);
        Thread t2 = new Thread(demo04);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(a);

    }
}
